package com.example.controller;

import com.example.entity.TShopProduct;
import com.example.entity.TShopUser;
import com.example.feign.ProductFeignApi;
import com.example.feign.UserFeignApi;
import com.example.service.ITShopOrderService;
import cpm.example.entity.TShopOrder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hc
 * @since 2025-09-08
 */
@Slf4j
@RestController
@RequestMapping("/order")
public class TShopOrderController {

    @Autowired
    private ITShopOrderService orderService;

    @Autowired
    private ProductFeignApi productFeignApi;
    @Autowired
    private UserFeignApi userFeignApi;


    @RequestMapping("/save/{pid}/{uid}/{number}")
    public TShopOrder save(@PathVariable("pid") Long pid,
                           @PathVariable("uid") Long uid,
                           @PathVariable("number") Integer number) {

        log.info("调用order服务的save方法");

        TShopProduct product = productFeignApi.get(pid);
        TShopUser user = userFeignApi.get(uid);

        TShopOrder order = new TShopOrder();
//        order.setPid(pid);
        order.setPid(product.getPid());
        order.setPname(product.getPname());
        order.setPprice(product.getPprice());


        order.setUid(uid);
        order.setUsername(user.getName());
        order.setNumber(number);
        orderService.save(order);
        return order;
    }

}
